/*
 * @Author: 'Chenfarry' '2925102113@qq.com'
 * @Date: 2024-07-22 10:57:37
 * @LastEditors: chenhuanhuan 2925102113@qq.com
 * @LastEditTime: 2024-11-15 15:35:01
 * @FilePath: \orderApp\store\user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

import type { UserType } from '@/service/business/login/type'

export const useUserStore = defineStore(
  'user',
  () => {
    // 用户信息
    const userInfo = ref<UserType>({ token: '' })

    const setUserInfo = (val: UserType) => {
      userInfo.value = val
    }
    const clearUserInfo = () => {
      userInfo.value = { token: '' }
    }

    const loginFormInfo=ref({contact:'',password:''})
    const setloginFormInfo = (val)=>{
      loginFormInfo.value = val
    }

    // 食堂单位代码
    const pinia_org = ref<UnitInfo>({})
    const setOrgVal = (val: UnitInfo) => {
      pinia_org.value = val
    }

    // 设备安全距离值
    const pinia_SafeVal = ref<SafeInfo>({})

    const setSafeVal = (val: SafeInfo) => {
      pinia_SafeVal.value = val
    }


    const isLogined = computed(() => !!userInfo.value.token)

    return {
      userInfo,
      setUserInfo,
      clearUserInfo,
      isLogined,
      setSafeVal,
      pinia_SafeVal,
      pinia_org,
      setOrgVal,
      loginFormInfo,
      setloginFormInfo,
    }
  },
  {
    persist: true,
  },
)
